<?
/******************************************
* ZEMPLATE
* ---------------------------
* A PHP template by Zenyai
* 
* For more information: http://code.google.com/p/zemplate/
* This project is under an open source license (Apache License, Version 2.0)
* http://www.apache.org/licenses/LICENSE-2.0
*
*******************************************/

// this function required HighChart javascript
/*
The script is configure to use in the project that I work with (School Project). So, it basically won't be
normally use in other field of work because it only generate house point's graph (groups in the school).
But feel free if you want to use it.
*/

class HighChart {
	function __construct($var) {
		$this->var = $var;
		include_once('zemplate/functions/LoadDB.functions.php');
	}
	
	function load() {
		$hChart = " <script type=\"text/javascript\"> 
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'barchart',
						defaultSeriesType: 'bar'
					},
					title: {
						text: '' . echo date(\"F\"); . 'House Points'
					},
					xAxis: {
						categories: ['Joshua', 'Peter', 'Solomon', 'Daniel', 'Joseph', 'David', 'Gideon', 'Moses', 'Timothy', 'Samson', 'Stephen', 'Paul'],
						title: {
							text: null
						}
					},
					yAxis: {
						min: 0,
						title: {
							text: '',
							align: 'high'
						}
					},
					tooltip: {
						formatter: function() {
							return ''+
								 this.series.name +': '+ this.y +' points';
						}
					},
					plotOptions: {
						bar: {
							dataLabels: {
								enabled: true
							}
						}
					},
					credits: {
						enabled: false
					},
				        series: [{
						name: 'House Points',
						data: [	";
$i = 1;
$month = intval(date("m"));
while ($i < "13") 
{	
$database = new LoadDB(array("house_pt", true, true, "house", $i, "month", $month));
$count = $database->getRow(0);
$hChart .= $count . ",";
$i++;
}
		$hChart .= "]
					}]
				});
				
				
			});
				
		</script> 
        
        <script type=\"text/javascript\"> 
		
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'piechart',
						plotBackgroundColor: null,
						plotBorderWidth: null,
						plotShadow: false,
						        defaultSeriesType: 'pie'
						
					},
					title: {
						text: ''
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
    
    plotOptions: {
        pie: {
            dataLabels: {
                distance: 15,
                color: 'white'
            }
        }
    },
										credits: {
						enabled: false
					},
				    series: [{
						data: [";
$i = "1";
while ($i < "13") 
{	
$database = new LoadDB(array("house_pt", true, true, "house", $i, "month", $month));
$count = $database->getRow(0);
if($count > "0"){
if($i == "1"){
	$i_name = "Joshua";
}elseif($i == "2"){
	$i_name = "Peter";
}elseif($i == "3"){
	$i_name = "Solomon";
}elseif($i == "4"){
	$i_name = "Daniel";
}elseif($i == "5"){
	$i_name = "David";
}elseif($i == "6"){
	$i_name = "Joseph";
}elseif($i == "7"){
	$i_name = "Gideon";
}elseif($i == "8"){
	$i_name = "Moses";
}elseif($i == "9"){
	$i_name = "Timothy";
}elseif($i == "10"){
	$i_name = "Samson";
}elseif($i == "11"){
	$i_name = "Stephen";
}elseif($i == "12"){
	$i_name = "Paul";
}
$hChart .= "['" . $i_name . "', " . "],";
}
$i++;
}

$hChart .=  "
						]
					}]
				});
			});
				
		</script> ";
		return $hChart;
	}
}
?>